﻿#pragma once

#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <time.h>
#include <locale.h>
#include <stdbool.h>

#define FOOD_NUM 3
#define BODY L'●'
#define BOARD L'◎'
#define FOOD L'★'
#define KEY_PRESS(kv) ((GetAsyncKeyState(kv) & 1 ) ? 1 : 0)

//蛇的方向
enum DIRECTION
{//上，下，左，右
	UP = 1,
	DOWN,
	LEFT,
	RIGHT
};

enum GAME_STATUS
{//正常，撞墙，撞自己，正常退出
	COMMON = 1,
	KILL_BY_WALL,
	KILL_BY_SELF,
	END_COMMON
};

//蛇的节点
typedef struct SnakeNode
{
	int x;
	int y;
	struct SnakeNode* next;
}SnakeNode;

//蛇的信息
typedef struct Snake
{
	SnakeNode* _psnake;//指向蛇头的指针
	SnakeNode* _food[FOOD_NUM];//指向食物的指针
	enum GAME_STATUS _status;//游戏状态
	enum DIRECTION _dir;//蛇头的方向
	int food_score;//食物的分数，默认为10
	int sum_score;//总分数
	int sleep_time;//蛇的速度
}Snake;

//游戏初始化
void Game_init();

//游戏开始
void Game_start(Snake* psnake);

//定位光标
void Setpos(int x, int y);

//地图边框绘制
void Drawmap();

//初始化蛇
void Initsnake(Snake* psnake);

//设置食物
void Setfood(Snake* psnake);

//游戏运行
void Game_ing(Snake* psnake);

//蛇的移动
void Snakemove(Snake* psnake);

//识别按键
void Keyboard(Snake* psnake);

//新节点坐标
void Setnewbody(SnakeNode* newbody, Snake* psnake);

//吃到食物
void Eatfood(SnakeNode* newbody, Snake* psnake, int foodnum);

//没吃到食物
void Noeatfood(SnakeNode* newbody, Snake* psnake);

//撞墙
//void Killbywall(Snake* psnake, SnakeNode* newbody);

//撞自己
void Killbyself(Snake* psnake);

//游戏结束
void Game_end(Snake* psnake);

//新创建的食物不与已有的食物重合
int Manyfood(Snake* psnake, int foodnum, SnakeNode* food);

//初始化食物
void Initfood(Snake* psnake);